//        myD3D.h
//-------------------------
// Name:    Richard Lindholm
// Pno:        850629****
// Created: 06/08/25 22:10
//-------------------------
//

#ifndef _MYD3D_H_
#define _MYD3D_H_

//-------------------------
// INCLUDES ETC.

#include <windows.h>
#include <d3dx9.h>
#include <d3d9.h>
#include <vector>
#include <string>

#pragma comment( lib, "d3d9.lib" )
#pragma comment( lib, "d3dx9.lib" )

//#define _RGB32( a,r,g,b ) ((b) + ((g) << 8) + ((r) << 16) + ((a) << 24))

enum RENDERPRIO{

    LOW_PRIO,
    MID_PRIO,
    HIG_PRIO,
    TOP_PRIO,
    MOUSE_PRIO
};

enum RENDERTYPE{

    TYPE_SPRITE,
    TYPE_TILE
};

//-------------------------
// CLASS & STRUCT

struct TextData{

    TextData( char* t, int x, int y, D3DXCOLOR c ) :
        text(t), xPos(x), yPos(y), color(c) {}
    
    std::string text;
    int xPos;
    int yPos;
    D3DXCOLOR color;
};

struct RenderData{

    RenderData( int _Texture, D3DXVECTOR3 _TexPos, D3DCOLOR _TexColor, RENDERTYPE _TexType ) :
        Texture(_Texture), TexPos(_TexPos), TexColor(_TexColor), TexType(_TexType) {}
    RenderData( int _Texture, D3DXVECTOR3 _TexPos, D3DCOLOR _TexColor, RENDERTYPE _TexType, RECT _TexSrc );

    int Texture;
    D3DXVECTOR3 TexPos;
    D3DCOLOR TexColor;
    RENDERTYPE TexType;
    RECT TexSrc;
};

class myD3D{

public:

    // con/destructor
    myD3D(){}
    myD3D( HWND hwnd, HINSTANCE hinstance );
    ~myD3D() { endD3D(); }

    // some 3D functions
    bool startD3D( HWND hwnd, HINSTANCE hinstance );
    void render();
    void endD3D();

    LPDIRECT3DDEVICE9 getDevice() { return m_device; }

    int AddTextureToList( char* filename );
    int AddEmptyTextureToList( UINT w, UINT h );
    void AddToRenderList( RenderData data, RENDERPRIO prio );

    void PlotPixel( UINT *video_buffer, UINT pitch, UINT x, UINT y, UINT r, UINT g, UINT b );

    void PrintText( int xPos, int yPos, const char* text, ... );
    void SetTextColor(D3DXCOLOR color) { m_textColor = color; }
    D3DXCOLOR GetTextColor() { return m_textColor; }

    void ClearRenderList();
    
    bool GetFullscreen() { return m_bFullscreen; }

    // textures
    std::vector<LPDIRECT3DTEXTURE9> m_texList;

private:

    bool m_debugInfo;

    HWND m_hwnd;

    // needed for debugtext
    ID3DXFont* m_font;
    TCHAR m_strFont[LF_FACESIZE];

    // sprite
    ID3DXSprite* m_sprite;

    std::vector<RenderData> m_RenderListLow;
    std::vector<RenderData> m_RenderListMid;
    std::vector<RenderData> m_RenderListHig;
    std::vector<RenderData> m_RenderListTop;
    std::vector<RenderData> m_RenderListMouse;

    std::vector<TextData> m_TextBuffer;

    // other d3d things
    LPDIRECT3D9 m_d3d;
    LPDIRECT3DDEVICE9 m_device;
    
    bool m_bFullscreen;

    D3DXCOLOR m_textColor;
};

// functions in myD3D.cpp

#endif